package crivia.eca.common;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;


public class ES {

	public static String bp(){
		ClassLoader tCLD = Thread.currentThread().getContextClassLoader();
		String f="classbean"+System.getProperty("file.separator");
		String f2="classbean/";
		String path="Unable Path.";
		try {
			Enumeration<URL> tURLs = tCLD.getResources("");
			while(tURLs.hasMoreElements()){
				URL tURL = tURLs.nextElement();
				path = java.net.URLDecoder.decode(tURL.getFile(), "utf-8");
				if (path.indexOf("jar!") > -1){
					continue;
				}
				if (path.endsWith(f)){
					return path.substring(0,path.indexOf(f));
				} else if (path.endsWith(f2)){
					return path.substring(0,path.indexOf(f2));
				}
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		} catch (Throwable e) {
			throw new RuntimeException("Base Path Not Found. ["+path+"]/["+f+"]",e);
		}
		throw new RuntimeException("Base Path Not Found. ["+path+"]/["+f+"]");
	}
	
	public static void main(String[] args) throws Exception {
//		String s="/D:/WEAVER/ecology/classbean/";
//		System.out.println(System.getProperty("file.separator"));
//		System.out.println(
//		s.indexOf("classbean"
//				+System.getProperty("file.separator")));
//		s=s.substring(0,s.indexOf("classbean"
//				+System.getProperty("file.separator")));
//		System.out.println(s);

		ClassLoader tCLD = Thread.currentThread().getContextClassLoader();
		String f="classbean"+System.getProperty("file.separator");
		String path="Unable Path.";
		Enumeration<URL> tURLs = tCLD.getResources("");
		while(tURLs.hasMoreElements()){
			URL tURL = tURLs.nextElement();
			path = java.net.URLDecoder.decode(tURL.getFile(), "utf-8");
			if (path.indexOf("jar!") > -1){
				continue;
			}
			System.out.println();
			System.out.println(path);
			System.out.println(f);
			if (path.endsWith(f)){
//				return ;
				System.out.println(path.substring(0,path.indexOf(f)));
			}
		}
	}
	
}
